package com.xiaolin.sports.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaolin.sports.dao.ChildSignInfoMapper;
import com.xiaolin.sports.dao.CourseInfoMapper;
import com.xiaolin.sports.dao.ParentInfoMapper;
import com.xiaolin.sports.model.ChildSignInfo;
import com.xiaolin.sports.model.CourseInfo;
import com.xiaolin.sports.model.ProductOrder;
import com.xiaolin.sports.model.SysUser;
import com.xiaolin.sports.page.Page;
import com.xiaolin.sports.reqVo.CourseSignVO;
import com.xiaolin.sports.service.ICourseService;
import com.xiaolin.sports.view.ChildSignView;
import com.xiaolin.sports.view.CourseBuyerView;
import com.xiaolin.sports.view.CourseListView;

@Service("courseService")
public class CourseServiceImpl implements ICourseService {

	@Autowired
	private CourseInfoMapper courseInfoMapper;
	@Autowired
	private ChildSignInfoMapper childSignInfoMapper;
	@Autowired
	private ParentInfoMapper parentInfoMapper;
	
	@Override
	public List<CourseInfo> selectListByPage(Page<CourseInfo> page) {
		return courseInfoMapper.selectListByPage(page);
	}

	@Override
	public CourseInfo selectByPrimaryKey(Integer id) {
		return courseInfoMapper.selectByPrimaryKey(id);
	}

	@Override
	public int addAndUpdateCourse(CourseInfo vo, SysUser user) {
		if(vo.getId() == null) {
			vo.setCreaterId(user.getIdUser());
			vo.setCreater(user.getUserName());
			vo.setCreateTime(new Date());
			courseInfoMapper.insertSelective(vo);
		}else {
			vo.setUpdaterId(user.getIdUser());
			vo.setUpdater(user.getUserName());
			vo.setUpdateTime(new Date());
			courseInfoMapper.updateByPrimaryKeySelective(vo);
		}
		return 1;
	}

	@Override
	public CourseListView selectCourseDetail(Integer id) {
		return courseInfoMapper.selectDetailById(id);
	}

	@Override
	public List<ChildSignView> selectCourseSignByPage(Page<ChildSignView> page) {
		return childSignInfoMapper.selectCourseSignByPage(page);
	}

	@Override
	public List<CourseBuyerView> selectBuyRecordByPage(Page<CourseBuyerView> page) {
		return parentInfoMapper.selectBuyRecordByPage(page);
	}

	@Override
	public int updateChildSignInfo(ChildSignInfo info) {
		return childSignInfoMapper.updateByPrimaryKeySelective(info);
	}

	@Override
	public ChildSignInfo selectChildSignById(Integer id) {
		return childSignInfoMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<CourseListView> selectListForWapByPage(Page<CourseListView> page) {
		return courseInfoMapper.selectListForWapByPage(page);
	}

	@Override
	public CourseListView selectForWapByParams(String openid, Integer courseId) {
		return courseInfoMapper.selectForWapByParams(openid, courseId);
	}

}
